package com.iqiyi.pps.epg.api.server.impl;

import com.alibaba.fastjson.JSON;
import com.iqiyi.mams.hedvig.rpc.client.ServiceHelper;
import com.iqiyi.pps.epg.api.model.web.query.TFilter;
import com.iqiyi.pps.epg.api.model.web.query.TResponse;
import com.iqiyi.pps.epg.api.server.iservice.ProgramApiService;
import com.iqiyi.pps.epg.api.server.proxy.ProgramProxy;
import com.iqiyi.pps.epg.api.server.proxy.StreamProxy;
import com.iqiyi.pps.epg.api.server.web.program.ProgramWebService;
import com.iqiyi.pps.epg.api.utils.Constants;
import com.iqiyi.pps.epg.api.utils.CrossDataLocalPool;
import com.iqiyi.pps.epg.api.utils.RegUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.ws.rs.FormParam;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by karkarrotxu on 2016/9/6.
 */
@Service("programApiServiceImpl")
public class ProgramApiServiceImpl extends ApiServiceImpl implements ProgramApiService {

    @Autowired
    private ProgramProxy programProxy;

    @Autowired
    private StreamProxy streamProxy;

    public String getRtmpStream( String qipuId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.getRtmpStream(qipuId);
    }

    @Override
    public String getProgramLogList(String programId, Integer pageNo, Integer pageSize) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.getProgramLogList(programId, pageNo, pageSize);
    }

    @Override
    public String programList(String programId,
                              String fatherId, String startDate,
                              String endDate, Integer pageNo,
                              Integer pageSize, String qipuId,
                              String pname, String freeStatus,
                              String bossStatus, String liveProgramType,
                              String channelName, String liveType,
                              String liveChannelType, String sortType,
                              String deleteStatus, String formal,
                              String playStatus, String episodeGrade,
                              String recommendRate, String hot, String test, String fromPath
    ) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.getProgramList(programId,
                fatherId, startDate, endDate, pageNo,
                pageSize, qipuId, pname, freeStatus,
                bossStatus, liveProgramType, channelName, liveType,
                liveChannelType, sortType, deleteStatus, formal,
                playStatus, episodeGrade, recommendRate, hot, test,fromPath);
    }


    @Override
    public String currentAndNextProgram(String fatherId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.currentAndNextProgram(fatherId);
    }

    @Override
    public String searchProgram(String name, String startDate, String endDate, String porgramQipuId, String channelQipuId, String channelName) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.searchProgram(name, startDate, endDate, porgramQipuId, channelQipuId, channelName);
    }


    @Override
    public String programEdit(String dataString, String imageDatas) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programEdit(dataString, imageDatas);
    }

    @Override
    public String programAdd(String dataString, String imageDatas) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programAdd(dataString, imageDatas);
    }

    @Override
    public String programDelete(String id) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programDelete(id);
    }

    public String searchFilterProgram(String qipuId, String programName, String channelName,
                                      String startDate, String endDate, String platforms) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.searchFilterProgram(qipuId, programName, channelName, startDate, endDate, platforms);
    }

    public String programToggleLock(String id,
                                    String fatherId,
                                    String lockType) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programToggleLock(id, fatherId, lockType);
    }

    @Override
    public String programMove(String id,
                              String flag,
                              String fatherId,
                              String operationDay) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programMove(id, flag, fatherId, operationDay);
    }

    @Override
    public String programInsertQuery(String qipuId, String pname,
                                     String startDate, String endDate,
                                     String minProgramTime, String maxProgramTime,
                                     Integer pageNo, Integer pageSize
    ) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programInsertQuery(qipuId, pname, startDate, endDate, minProgramTime, maxProgramTime, pageNo, pageSize);
    }

    @Override
    public String programIndexMove(String id, String aimId, String dateTime, String channelId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programIndexMove(id, aimId, dateTime, channelId);
    }


    public String programBatchDel(String ids, String dateTime, String channelId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programBatchDel(ids, dateTime, channelId);
    }

    public String programBatchAdd(String dataString, String beginTime, String fatherId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programBatchAdd(dataString, beginTime, fatherId);
    }

    @Override
    public String getProgramBroadcastControl(long programId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.getProgramBroadcastControl(programId);
    }

    @Override
    public String setProgramBroadcastControl(long programId,
                                             String params,
                                             long channelId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.setProgramBroadcastControl(programId, params, channelId);
    }

    @Override
    public String getLivingInfo() {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.getLivingInfo();
    }

    @Override
    public String programSyncTVMao(String fatherId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programSyncTVMao(fatherId);
    }

    @Override
    public String syncProgram(String fatherId, String programId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.syncProgram(fatherId, programId);
    }

    @Override
    public String proxyToPuYu(String barCode, String cprVideoName) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.proxyToPuYu(barCode, cprVideoName);
    }

    @Override
    public String programDaySort(String fatherId, String sortDate) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programDaySort(fatherId, sortDate);
    }

    @Override
    public String programForceCheck(long programId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programForceCheck(programId);
    }

    @Override
    public String recordStreamError(String errorCode,
                                    String channelId,
                                    String programId,
                                    String obj,
                                    String errorAll) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.recordStreamError(errorCode, channelId, programId, obj, errorAll);
    }

    public String programMaxDuration(String fatherId) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.programMaxDuration(fatherId);
    }

    public String getYesterdayEndTime(String channelId, String newStartTime) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.getYesterdayEndTime(channelId, newStartTime);
    }

    public String getNetMonitorInfo(long channelQipuId){
        CrossDataLocalPool.set(getCrossData());
        return streamProxy.getNetMonitorInfo(channelQipuId);
    }

    public String updateBySport(String programQipuId,String newStartTime,String newStopTime ){
        CrossDataLocalPool.set(getCrossData());
        return programProxy.updateBySport(programQipuId,newStartTime,newStopTime);
    }

    public String unbindSport( String programQipuId, String matchId){
        CrossDataLocalPool.set(getCrossData());
        return programProxy.unbindSport(programQipuId,matchId);
    }

    @Override
    public String saveOAInfo( String data) {
        CrossDataLocalPool.set(getCrossData());
        return programProxy.saveOAInfo(data);
    }
}
